#ifndef NETWORKCLIENT_H
#define NETWORKCLIENT_H

#include <QObject>
#include <QDebug>
#include <QTcpSocket>
#include <QAbstractSocket>
#include <QJsonObject>
#include <QTimer>

class NetworkClient : public QObject
{
  Q_OBJECT
public:
  explicit NetworkClient(QObject *parent = 0);
  void connectToHost();
  void disconnectFromHost();
  bool isConnected();
  void configureNetwork(const QJsonObject &settings);
signals:
  void dataReady(QByteArray);
  void socketError(const int &errorCode, const QString &errorString);
public slots:
  void connected();
  void disconnected();
  void bytesWritten(qint64 bytes);
  void readyRead();
  void networkError(QAbstractSocket::SocketError error);//Network error
  void connectToHostTriggered();
private:
  QTcpSocket *socket;
  quint16 connectAttempts;
  quint16 connectTimeout;
  QString serverIP;
  quint16 serverPort;
  quint16 connectAttemptCounter;
};

#endif // NETWORKCLIENT_H
